<!--
 * @Descripttion: 生态同质化区域分析
-->
<template>
  <div class="eco-homo-wrapper">
    <!-- 地图 -->
    <div class="page-map">
      <map-view @initMapView="initMapViewHandler"></map-view>
    </div>
    <!-- 弹框 -->
    <HomoModal @mapRender="mapRender" :view="view" @locationHandler="locationHandler" />
  </div>
</template>
<script>
// 地图组件
import MapView from "@/components/yc/MapView";
// 弹框
import HomoModal from "../components/HomoModal";
import GeometryUtils from "@/utils/yc/GeometryUtils";
import QueryUtils from "@/utils/yc/QueryUtils";
import LayerUtils from "@/utils/yc/LayerUtils";
import SymbolUtils from "@/utils/yc/SymbolUtils";
import { highlightByGeometryList } from "lark-map";
export default {
  name: "EcoHomo",
  components: {
    MapView,
    HomoModal
  },
  data() {
    return {
      //地图对象
      view: null
    };
  },
  created(){
    this.$emit("closeMenu")
  },
  methods: {
    /**
     * 初始化地图对象
     */
    initMapViewHandler(evt) {
      this.view = evt;
    },
    // 地图渲染
    mapRender(data) {
      const graphics = GeometryUtils.setSymbolByFeatures(
        data,
        this.view.spatialReference
      );
      let geometries = [];
      let symbols = [];
      graphics.forEach(graphic => {
        geometries.push(graphic.geometry);
        symbols.push(graphic.symbol);
      });
      highlightByGeometryList({
        view: this.view,
        geometryList: geometries,
        symbol: symbols
      });
      // LayerUtils.getRenderDrawLayer(this.view).addMany(graphics);
    },
    /**
     * 定位
     */
    async locationHandler(row) {
      LayerUtils.clearRenderDrawLayer(this.view);
      if (row && row.hasOwnProperty("xzqdm")) {
        let code = row.xzqdm;
        let feature = null;
        if (code === "150125") {
          feature = await QueryUtils.queryAreaByCode(
            "xzq",
            this.view,
            "150125"
          );
        } else {
          feature = await QueryUtils.queryAreaByCode(
            "xzqByCode",
            this.view,
            code
          );
        }
        if (feature) {
          if (code != "150125") {
            feature.symbol = SymbolUtils.HIGHLIGHT_RENDER;
            LayerUtils.getRenderDrawLayer(this.view).add(feature);
          }
          this.view.goTo(feature);
        }
      }
    }
  }
};
</script>
<style lang="scss" scoped>
.eco-homo-wrapper {
  position: relative;
  width: 100%;
  height: 100%;

  .page-map {
    position: relative;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
  }
}
</style>